package cn.project.lemontree.utils;

import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class ShiroConfig {

    @Bean
    public MyRealm getMyRealm(){
        return new MyRealm();
    }

    //对web工程认证安全管理器类
    @Bean
    public DefaultWebSecurityManager getDefaultWebSecurityManager(){
        DefaultWebSecurityManager dws =  new DefaultWebSecurityManager();
        dws.setRealm(this.getMyRealm());
        return dws;
    }

    //那些用户可以不用经过登录直接访问系统资源
    @Bean
    public ShiroFilterFactoryBean shiroFilterFactoryBean(){
        ShiroFilterFactoryBean filter = new ShiroFilterFactoryBean();
        filter.setSecurityManager(getDefaultWebSecurityManager());
        filter.setLoginUrl("/login.html");
        filter.setUnauthorizedUrl("/login.html");
        Map<String,String> map = new HashMap<>();
        map.put("/**","anon");
//        map.put("/jeasyui/**","anon");  //匿名
//        map.put("/user/login","anon");
//        map.put("/**","authc"); //认证
        map.put("/logout","logout");
        filter.setFilterChainDefinitionMap(map);
        return filter;
    }
}